package com.zy.imagineCommunity.controller;

import com.zy.imagineCommunity.service.BlogService;
import com.zy.imagineCommunity.service.CommentService;
import com.zy.imagineCommunity.service.PostService;
import com.zy.imagineCommunity.service.UserSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Controller
public class IndexController {

    @Autowired
    UserSerivce userSerivce;

    @Autowired
    BlogService blogService;

    @Autowired
    PostService postService;

    @Autowired
    CommentService commentService;

    /**
     * 前台系统首页
     *
     * @return
     */
    @GetMapping("/index")
    public String getIndex() {
        return "/index";
    }

    /**
     * 后台系统首页
     *
     * @param model
     * @return
     */
    @GetMapping("/managementIndex")
    public String getManagementIndex(Model model) {

        int userCount = userSerivce.queryUserTotalCount();
        model.addAttribute("userCount", userCount);

        int blogCount = blogService.queryBlogCountTotal();
        model.addAttribute("blogCount", blogCount);

        int postCount = postService.queryPostCountTotal();
        model.addAttribute("postCount", postCount);

        int commentCount = commentService.queryCommentsCountTotal();
        model.addAttribute("commentCount", commentCount);

        int replyCount = commentService.queryReplyCountTotal();
        model.addAttribute("replyCount", replyCount);

        return "/ManagementIndex";
    }

    /**
     * 后台系统版块首页
     *
     * @param model
     * @param type
     * @return
     */
    @GetMapping("/managementIndexByType/{type}")
    public String getManagementIndexByType(Model model, @PathVariable("type") int type) {

        int userCount = userSerivce.queryUserTotalCount();
        model.addAttribute("userCount", userCount);

        int blogCount = blogService.queryBlogCountTotalByType(type);
        model.addAttribute("blogCount", blogCount);

        int commentCount = commentService.queryCommentsCountTotalByType(type);
        model.addAttribute("commentCount", commentCount);

        int replyCount = commentService.queryReplyCountTotalByType(type);

        model.addAttribute("replyCount", replyCount);

        return "/ManagementIndexByType";
    }

}
